/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ipo.mm.ejb.entities;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author makcro
 */
@Entity
@Table(name = "INSTITUTION")
@NamedQueries({
    @NamedQuery(name = "Institution.findAllWithFlagDeleted", query = "SELECT i FROM Institution i"),
    @NamedQuery(name = "Institution.findAll", query = "SELECT i FROM Institution i WHERE i.deleted = false order by i.name"),
    @NamedQuery(name = "Institution.findById", query = "SELECT i FROM Institution i WHERE i.id = :id"),
    @NamedQuery(name = "Institution.findByName", query = "SELECT i FROM Institution i WHERE i.name = :name"),
    @NamedQuery(name = "Institution.findByEmail", query = "SELECT i FROM Institution i WHERE i.email = :email"),
    @NamedQuery(name = "Institution.findByAddress", query = "SELECT i FROM Institution i WHERE i.address = :address"),
    @NamedQuery(name = "Institution.findByZip", query = "SELECT i FROM Institution i WHERE i.zip = :zip"),
    @NamedQuery(name = "Institution.findByTelephone", query = "SELECT i FROM Institution i WHERE i.telephone = :telephone"),
    @NamedQuery(name = "Institution.findByFax", query = "SELECT i FROM Institution i WHERE i.fax = :fax"),
    @NamedQuery(name = "Institution.findByNote", query = "SELECT i FROM Institution i WHERE i.note = :note"),
    @NamedQuery(name = "Institution.findByDeleted", query = "SELECT i FROM Institution i WHERE i.deleted = :deleted"),
    @NamedQuery(name = "Institution.findWithEmail", query = "SELECT i FROM Institution i WHERE i.deleted = false and i.email IS NOT NULL and LENGTH(i.email)>2")})
    public class Institution implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID")
    private Integer id;
    @Column(name = "Name")
    private String name;
    @Column(name = "Email")
    private String email;

    @Column(name = "Web")
    private String web;

    @Column(name = "Address")
    private String address;
    @Column(name = "Zip")
    private String zip;
    @Column(name = "Telephone")
    private String telephone;
    @Column(name = "Fax")
    private String fax;
    @Column(name = "Note")
    private String note;
    @Basic(optional = false)
    @Column(name = "Deleted")
    private boolean deleted;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "institution", fetch=FetchType.EAGER)
    private Collection<Representative> representativeCollection;
    @JoinColumn(name = "Type", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private InstitutionType type;
    @JoinColumn(name = "City", referencedColumnName = "ID")
    @ManyToOne
    private City city;
    @JoinColumn(name = "Family", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private InstitutionFamily family;
    @JoinColumn(name = "Region", referencedColumnName = "ID")
    @ManyToOne(optional = false)
    private InstitutionRegion region;
    @JoinColumn(name = "User", referencedColumnName = "Username")
    @ManyToOne(optional = false)
    private User user;

    public Institution() {
    }

    public Institution(Integer id) {
        this.id = id;
    }

    public Institution(Integer id, boolean deleted) {
        this.id = id;
        this.deleted = deleted;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getWeb() {
        return web;
    }

    public void setWeb(String web) {
        this.web = web;
    }

    
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String getTelephone() {
        return telephone;
    }

    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public Collection<Representative> getRepresentativeCollection() {
        return representativeCollection;
    }

    public void setRepresentativeCollection(Collection<Representative> representativeCollection) {
        this.representativeCollection = representativeCollection;
    }

    public InstitutionType getType() {
        return type;
    }

    public void setType(InstitutionType type) {
        this.type = type;
    }

    public City getCity() {
        return city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public InstitutionFamily getFamily() {
        return family;
    }

    public void setFamily(InstitutionFamily family) {
        this.family = family;
    }

    public InstitutionRegion getRegion() {
        return region;
    }

    public void setRegion(InstitutionRegion region) {
        this.region = region;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Institution)) {
            return false;
        }
        Institution other = (Institution) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.ipo.mm.ejb.entities.Institution[id=" + id + "]";
    }

}
